package com.hxd.otc.module.order.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.order.bean.AppealBean;
import com.hxd.otc.module.order.contract.MyApplealContract;
import com.hxd.otc.module.order.model.AllOrderModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.List;

/**
 * 作  者 :  zjl
 * 时  间 :  2018/6/4 17:02
 * 描  述 :  ${所有订单页面P}
 */
public class MyAppleaPresenter extends BasePresenter<MyApplealContract.View> implements MyApplealContract.Presenter {

    AllOrderModel model;

    public MyAppleaPresenter(MyApplealContract.View view) {
        super(view);
        model = AllOrderModel.getInstance();
    }

    @Override
    public void start() {

    }


    @Override
    public void doLoadData(boolean isRefresh) {

        model.getAppealList(new BaseObserver<List<AppealBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull List<AppealBean> list) {
                doSetAdapter(list);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.onError(errType);
                mView.showToast(errMessage);
                doShowNoMore();
            }


        }, mView.<BaseBean<List<AppealBean>>>bindAutoDispose());
    }

    @Override
    public void doSetAdapter(List<AppealBean> list) {
        doShowNoMore();
        mView.onSetAdapter(list);
    }


    @Override
    public void doShowNoMore() {
        mView.onShowNoMore();
    }

    @Override
    public void cancleAppeal(String appealId) {
        model.cancleAppeal(new BaseObserver() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.cancleSuccedd();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose(), appealId);
    }


}
